import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn,ManyToOne,ManyToMany} from 'typeorm'
import {User} from './User'
import {Tags} from './Tags'
import { type } from 'os'
@Entity({ name: 'posts' })
export class Posts {
  @PrimaryGeneratedColumn({
    type: 'int',
    comment: '主键id'
  })
  id: number

  @Column({
    type: 'varchar',
    unique: true, //是否唯一 
    nullable: false, //值是否可以为null
    name: 'title',
    length: 50,
    comment: '标题'
  })
  title: string

  @Column({
    type: 'varchar',
    nullable: true,
    unique: false,
    length: 100,
    name: 'content',
    comment: '内容'
  })
  content: string

  @Column({
    type: 'tinyint',
    name: 'is_del',
    default:()=>0,
    comment: '是否可以删除,0-可以，1-不可以'
  })
  idDel: 'string'

  @CreateDateColumn({
    type: 'timestamp',
    nullable: false,
    comment: '创建时间',
    name: 'create_time',
  })
  createTime: Date
  @UpdateDateColumn({
    type: 'timestamp',
    nullable: false,
    comment: '更新时间',
    name: 'update_time',
  })
  updateTime: Date

  @ManyToOne(type=>User, user=>user.posts)
  user:User

  @ManyToMany(type=>Tags,tag=>tag.posts)
  tags:Tags[]
}